<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>选课系统注册界面</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            background-color: #f7f7f7;
        }
        .register-container {
            background-color: white;
            padding: 20px;
            border-radius: 5px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 300px;
        }
        .register-container h2 {
            text-align: center;
            margin-bottom: 20px;
        }
        .form-group {
            margin-bottom: 15px;
            position: relative;
        }
        .form-group label {
            display: block;
            margin-bottom: 5px;
        }
        .form-group input {
            width: 100%;
            padding: 8px;
            box-sizing: border-box;
            border: 1px solid #ccc;
            border-radius: 3px;
        }
        .form-group .send-code {
            right: 0;
            top: 0;
            padding: 8px 15px;
            border: none;
            border-radius: 3px;
            background-color: #007BFF;
            color: white;
            cursor: pointer;
        }
        .form-group .send-code:hover {
            background-color: #0056b3;
        }
        .register-button {
            text-align: center;
            margin-top: 20px;
        }
        .register-button button {
            padding: 10px 20px;
            font-size: 16px;
            background-color: green;
            color: white;
            border: none;
            border-radius: 3px;
            cursor: pointer;
        }
        .register-button button:hover {
            background-color: darkgreen;
        }
        .login-link {
            text-align: center;
            margin-top: 15px;
        }
        .login-link a {
            color: #007BFF;
            text-decoration: none;
        }
        .login-link a:hover {
            text-decoration: underline;
        }
        #code{
            width: 60%;
            float: left;
            margin-right: 20px;
        }
    </style>
</head>
<body>
<div class="register-container">
    <h2>选课系统注册</h2>
    <form action="register" method="post">
        <div class="form-group">
            <label for="phone">账号</label>
            <input type="text" id="username" name="username" required>
        </div>
        <div class="form-group">
            <label for="phone">手机号</label>
            <input type="text" id="phone" name="phone" required>
        </div>
        <div class="form-group">
            <label for="password">密码</label>
            <input type="password" id="password" name="password" required>
        </div>
        <div class="form-group">
            <label for="confirm-password">确认密码</label>
            <input type="password" id="confirm-password" name="confirm-password" required>
        </div>
        <div class="form-group">
            <label for="code">验证码</label>
            <input type="text" id="code" name="code" required>
            <button type="button" class="send-code" onclick="sendCode()">发送验证码</button>
        </div>
        <div class="register-button">
            <button type="submit">注册</button>
        </div>
        <% if (request.getAttribute("msg") != null) { %>
        <div style="color:red;"><%= request.getAttribute("msg") %></div>
        <% } %>
    </form>
    <div class="login-link">
        <a href="login.jsp">已有账号？点击登录</a>
    </div>
</div>

<script>
    function sendCode() {
        const phone = document.getElementById('phone').value;
        const password = document.getElementById('password').value;
        const confirmPassword = document.getElementById('confirm-password').value;
        const phoneRegex = /^1\d{10}$/;

        if (!phoneRegex.test(phone)) {
            alert('请输入正确的11位手机号');
            return;
        }

        if (password !== confirmPassword) {
            alert('两次输入的密码不一致');
            return;
        }

        // 这里只是模拟发送验证码，实际应用中需要请求服务器发送验证码
        alert('验证码已发送');
    }
</script>
</body>
</html>
